package com.customer.crm.customer.controller;

import com.customer.crm.customer.pojo.Contacts;
import com.customer.crm.customer.service.ContactsService;
import com.customer.crm.system.pojo.SystemUser;
import com.customer.crm.system.service.SystemUserService;
import com.customer.crm.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * The type Contacts controller.
 *
 * @author Lyp
 * @create 2021 /12/24
 */
@Controller
@RequestMapping("/manage/contacts")
public class ContactsController {


    /**
     * The Contacts service.
     */
    @Autowired
    ContactsService contactsService;

    @Autowired
    SystemUserService systemUserService;

    /**
     * To contact string.
     *      联系人页面
     * @return the string
     */
    @RequestMapping("/ContactsAction_list.action")
    public String toContact(){
        return "views/manage/contacts/list_contacts";
    }


    /**
     * Page model map.
     *      获取数据
     * @param page the page
     * @param rows the rows
     * @return the model map
     */
    @RequestMapping("/ContactsAction_findByPage.action")
    @ResponseBody
    public ModelMap page(Long page , Long rows){
        ModelMap modelMap = new ModelMap();
        ModelMap modelMap1 = new ModelMap();
        List<Contacts> listPage = contactsService.page(page, rows);
        List<Contacts> list = contactsService.list();
        modelMap.put("totalRows" , list.size());
        modelMap.put("result" , listPage);
        modelMap1.put("data" , modelMap);
        return modelMap1;
    }


    /**
     * See string.
     *查看
     * @param id the id
     * @return the string
     */
    @RequestMapping("/ContactsAction_see.action")
    public String  see(@RequestParam("id") Integer id){
        Contacts contacts = contactsService.findContactsById(id);
        ModelMap modelMap = new ModelMap();
        modelMap.put("contacts" , contacts);
        return "views/manage/contacts/see_contacts";
    }

    @RequestMapping("/ContactsAction_edit.action")
    public String  toAdd(ModelMap modelMap){
        List<SystemUser> list = systemUserService.list();
        modelMap.put("list" , list);
        return "views/manage/contacts/edit_contacts";
    }
}

